package com.elsa.smart_buffet.service.impl;

import com.elsa.smart_buffet.mapper.OrderTempMapper;
import com.elsa.smart_buffet.pojo.OrderTemp;
import com.elsa.smart_buffet.pojo.ResultBox.CallBackMessage;
import com.elsa.smart_buffet.pojo.ResultBox.ResponseResult;
import com.elsa.smart_buffet.service.OrderTempService;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @ClassName : OrderTempServiceImpl  //类名
 * @Author : elsa //作者
 */
@Service
@Transactional
public class OrderTempServiceImpl implements OrderTempService {

    @Autowired
    private OrderTempMapper orderTempMapper;

    @Override
    public ResponseResult insertOrderTemp(List<Map<String, Object>> list) throws InterruptedException {

        OrderTemp orderTemp = new OrderTemp();

        String res = "";

        try {
            for (Map<String, Object> stringObjectMap : list) {

                String mId = stringObjectMap.get("mId").toString();
                orderTemp.setMId(mId);


                String cId = stringObjectMap.get("cId").toString();
                orderTemp.setCId(cId);

                String moNum = stringObjectMap.get("moNum").toString();
                orderTemp.setMoNum(moNum);

                orderTempMapper.insert(orderTemp);

                res = "成功保存";
            }
        } catch (Exception e) {
            res = e.getMessage();
        }

        return new ResponseResult(CallBackMessage.SUCCESS, res);
    }

    @Override
    public ResponseResult selectOrderTemp() {
        List<OrderTemp> orderTempList = orderTempMapper.selectList(null);

        return new ResponseResult(CallBackMessage.SUCCESS, orderTempList);
    }

    @Override
    public ResponseResult deleteOrderTemp() {
        orderTempMapper.delete(null);
        return new ResponseResult(CallBackMessage.SUCCESS, "成功删除");
    }

}
